package com.mdd.front.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.entity.BannerSetting;
import com.mdd.common.entity.UserNotice;
import com.mdd.common.mapper.BannerSettingMapper;
import com.mdd.common.mapper.UserNoticeMapper;
import com.mdd.common.util.TimeUtils;
import com.mdd.front.service.IOtherService;

@Service
public class OtherServiceImpl implements IOtherService {

	@Autowired
	private BannerSettingMapper bannerSettingMapper;
	@Autowired
	private UserNoticeMapper userNoticeMapper;
	
	@Override
	public AjaxResult<List<BannerSetting>> qryBannerList(Integer userId, Integer type,Integer businessType) {
		List<BannerSetting> list = bannerSettingMapper.selectList(new LambdaQueryWrapper<BannerSetting>().eq(BannerSetting::getType, type)
				.eq(BannerSetting::getBusinessType, businessType));
		return AjaxResult.success(list);
	}

	@Override
	public AjaxResult<UserNotice> qrykdNotice(Integer userId) {
		UserNotice userNotice = userNoticeMapper.selectOne(new LambdaQueryWrapper<UserNotice>().eq(UserNotice::getUserId, userId).last("limit 1"));
		if(null == userNotice) {
			userNotice = new UserNotice();
			userNotice.setUserId(userId);
			userNotice.setCreateTime(TimeUtils.timestamp());
			userNoticeMapper.insert(userNotice);
			userNotice = userNoticeMapper.selectOne(new LambdaQueryWrapper<UserNotice>().eq(UserNotice::getUserId, userId).last("limit 1"));
		}
		return AjaxResult.success(userNotice);
	}

	@Override
	public AjaxResult<Object> setkdNotice(Integer userId, Integer type) {
		UserNotice userNotice = userNoticeMapper.selectOne(new LambdaQueryWrapper<UserNotice>().eq(UserNotice::getUserId, userId).last("limit 1"));
		if(null == userNotice) {
			userNotice = new UserNotice();
			userNotice.setUserId(userId);
			userNotice.setCreateTime(TimeUtils.timestamp());
			userNoticeMapper.insert(userNotice);
			return AjaxResult.success();
		}
		switch (type) {
		case 1:
			userNotice.setNoticeOne(userNotice.getNoticeOne()==1?0:1);
			break;
		case 2:
			userNotice.setNoticeTwo(userNotice.getNoticeTwo()==1?0:1);
			break;
		case 3:
			userNotice.setNoticeThree(userNotice.getNoticeThree()==1?0:1);
			break;
		case 4:
			userNotice.setNoticeFour(userNotice.getNoticeFour()==1?0:1);
			break;
		case 5:
			userNotice.setNoticeFive(userNotice.getNoticeFive()==1?0:1);
			break;
		case 6:
			userNotice.setNoticeSix(userNotice.getNoticeSix()==1?0:1);
			break;
		case 7:
			userNotice.setNoticeSeven(userNotice.getNoticeSeven()==1?0:1);
			break;
		case 8:
			userNotice.setNoticeEight(userNotice.getNoticeEight()==1?0:1);
			break;
		case 9:
			userNotice.setNoticeNine(userNotice.getNoticeNine()==1?0:1);
			break;
		default:
			break;
		}
		userNoticeMapper.updateById(userNotice);
		return AjaxResult.success();
	}

	@Override
	public AjaxResult<Object> setkdNoticeDefault(Integer userId, Integer type) {
		UserNotice userNotice = userNoticeMapper.selectOne(new LambdaQueryWrapper<UserNotice>().eq(UserNotice::getUserId, userId).last("limit 1"));
		if(null == userNotice) {
			userNotice = new UserNotice();
			userNotice.setUserId(userId);
			userNotice.setCreateTime(TimeUtils.timestamp());
			userNoticeMapper.insert(userNotice);
			return AjaxResult.success();
		}
		if(1 == type) {
			userNotice.setNoticeOne(1);
			userNotice.setNoticeTwo(1);
			userNotice.setNoticeThree(1);
			userNotice.setNoticeFour(1);
		}else if(2 == type) {
			userNotice.setNoticeFive(1);
			userNotice.setNoticeSix(1);
			userNotice.setNoticeSeven(1);
			userNotice.setNoticeEight(1);
			userNotice.setNoticeNine(1);
		}
		userNoticeMapper.updateById(userNotice);
		return AjaxResult.success();
	}

	

}
